﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Iooogle.Bms.Business;
using Com.Iooogle.Bms.Core;
using Com.Iooogle.Bms.Entities;

namespace Com.Iooogle.Bms.Web.Console
{
	/// <summary>
	/// 管理后台 - 项目管理。
	/// </summary>
	public partial class Projects : BasePage
	{
		/// <summary>
		/// 页面加载。
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack) {
				switch (this.Viewer) {
					case "CreateNew":
						ProCreatePanel.Visible = true;
						break;
					default:
						ProListPanel.Visible = true;

						TProjects T = new TProjects();
						Repeater1.DataSource = T.GetAll();
						Repeater1.DataBind();
						break;
				}
			} else {

			}
		}

		/// <summary>
		/// 创建项目。
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Button1_Click(object sender, EventArgs e)
		{
			ProjectsTable entity = new ProjectsTable();
			entity.ProName = TextBox1.Text.Trim();

			TProjects T = new TProjects();

			// 检查项目名称是否存在？
			if (!T.Exists(entity.ProName)) {
				T.Create(entity);

				Response.Redirect("Projects.aspx");
			} else {
				Response.Redirect(Request.UrlReferrer.PathAndQuery);
			}
		}
	}
}
